package com.iotimc.greendao;

import org.greenrobot.greendao.generator.DaoGenerator;
import org.greenrobot.greendao.generator.Entity;
import org.greenrobot.greendao.generator.Property;
import org.greenrobot.greendao.generator.Schema;

public class BuildDao {
    public static void main(String[] args) throws Exception {
        Schema schema = new Schema(1000, "com.iotimc.attendancesystem.dao");
        addPerson(schema);
        new DaoGenerator().generateAll(schema, "./app/src/main/java");
    }

    private static void addPerson(Schema schema) {
        Entity personEntity = schema.addEntity("PersonEntity");
        personEntity.addIdProperty().primaryKey().autoincrement();
        personEntity.addStringProperty("code").unique();
        personEntity.addStringProperty("name");
        //职位
        personEntity.addStringProperty("position");
        //是否为管理员
        personEntity.addBooleanProperty("admin");
        personEntity.addDateProperty("createTime");


        Entity attendanceLogEntity = schema.addEntity("AttendanceLogEntity");
        attendanceLogEntity.addIdProperty().primaryKey().autoincrement();
        attendanceLogEntity.addDateProperty("createTime");
        Property personId = attendanceLogEntity.addStringProperty("personfk").notNull().getProperty();
        attendanceLogEntity.addToOne(personEntity, personId);

        Entity doorLogEntity = schema.addEntity("DoorLogEntity");
        doorLogEntity.addIdProperty().primaryKey().autoincrement();
        doorLogEntity.addDateProperty("createTime");
        Property personId2 = doorLogEntity.addStringProperty("personfk").notNull().getProperty();
        doorLogEntity.addToOne(personEntity, personId2);
    }

}
